package application.view
{
	import application.model.vo.LevelVO;
	import away3d.containers.ObjectContainer3D;
	import away3d.materials.BitmapMaterial;
	import away3d.primitives.Plane;
	import core.Alert;
	import core.Size;
	import flash.events.Event;
	import flash.geom.Vector3D;
	
	/**
	 * ...
	 * @author Tiago Salomon
	 */
	public class LevelView extends ObjectContainer3D
	{
		private var _levelVO		:LevelVO;
		private var _floor			:FloorView;
		private var _wall			:WallView;
		private var _goal			:GoalView;
		private var _crate			:CrateView;
		
		public function LevelView() 
		{			
		}
		
		private function buildGrid():void 
		{
			
			SceneHolder.view.camera.lookAt(new Vector3D(this.x, this.y, this.z));
			
			for (var i:uint = 0; i < this._levelVO.grid.length; i++) 
			{
				for (var j:uint = 0; j < this._levelVO.grid[i].length; j++) 
				{
					
					switch (this._levelVO.grid[i][j]) 
					{
						case 0 :
							_floor = new FloorView();
							_floor.moveTo(Size.CUBE * j, 0, Size.CUBE * i);
							this.addChild(_floor);
							
							break;
							
						case 1 :
							_floor = new FloorView();
							_floor.moveTo(Size.CUBE * j, 0, Size.CUBE * i);
							this.addChild(_floor);
							
							_wall = new WallView();
							_wall.moveTo(Size.CUBE * j, 0, Size.CUBE * i);							
							this.addChild(_wall);
							
							break;
							
						case 2 :
							
							_floor = new FloorView();
							_floor.moveTo(Size.CUBE * j, 0, Size.CUBE * i);
							this.addChild(_floor);
							
							_goal = new GoalView();
							_goal.moveTo(Size.CUBE * j, 0.01, Size.CUBE * i);							
							this.addChild(_goal);
							
							break;
							
						case 3 :
							
							_floor = new FloorView();
							_floor.moveTo(Size.CUBE * j, 0, Size.CUBE * i);
							this.addChild(_floor);
														
							_crate = new CrateView("Crate"+i+j);
							_crate.moveTo(Size.CUBE * j, Size.CUBE / 2 + 0.1, Size.CUBE * i);
							this.addChild(_crate);
							
							break;
							
						case 4 :
							
							_floor = new FloorView();
							_floor.moveTo(Size.CUBE * j, 0, Size.CUBE * i);
							this.addChild(_floor);
							
							break;
						
					}
				}
			}
			
			SceneHolder.scene.addChild(this);			
			
		}
		
		public function show():void 
		{
			this.buildGrid();
		}

		public function hide():void 
		{
			
		}
		
		public function set levelVO(value:LevelVO):void 
		{
			_levelVO = value;
		}
		
	}

}